package com.example.springwebdemo1.dao.impl;

import cn.hutool.core.io.IoUtil;
import com.example.springwebdemo1.dao.UserDao;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@Repository//将当前类交给ioc容器进行统一管理
//@Component
public class UserDaoImpl1 implements UserDao {
    public List<String> findAll(){
        //1.加载并读取user.txt文件，获取用户数据
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("user.txt");
        if (in == null) {
            throw new RuntimeException("user.txt 文件未找到，请确保文件存在于 classpath 下");
        }
        ArrayList<String> lines= IoUtil.readLines(in, StandardCharsets.UTF_8, new ArrayList<>());
        return lines;
    }
}
